<template>
    <div class="page-100">
        <div class="repair-tab-part">

            <TabsComponent
                    :tabs="tabsOne"
                    :current="tabIndex"
                    v-on:tab-switch="switchHandler"/>
        </div>

        <!--一个按钮的时候-->
        <div class="button-backgrond" v-if="isshowButton">
            <yd-button  size="large" type="primary" @click.native="buttonClick" style="background-color:#3cc8a8;color:white">{{buttonName}}
            </yd-button>
        </div>

        <!--&lt;!&ndash;两个按钮的时候 审核&ndash;&gt;-->
        <div class="mui-flex button-backgrond" v-if="isshowshenhe">
            <div class="cell" >
                <yd-button  size="large" type="primary" @click.native="buttonexamineacceptClick" style="background-color:#3cc8a8;color:white;border-right: 1px solid #ffffff ">
                    同意
                </yd-button>
            </div>
            <div class="cell">
                <yd-button  size="large" type="primary" @click.native="buttonexaminerefuseClick" style="background-color:#3cc8a8;color:white;border-left: 1px solid #ffffff ">
                    拒绝
                </yd-button>
            </div>
        </div>

        <!--&lt;!&ndash;两个按钮的时候 经办&ndash;&gt;-->
        <div  class="mui-flex button-backgrond" v-if="isshowjingban">
            <div class="cell" >
                <yd-button  size="large" type="primary" @click.native="buttonoperateNowClick" style="background-color:#3cc8a8;color:white;border-right: 1px solid #ffffff ">
                    立即处理
                </yd-button>
            </div>
            <div class="cell">
                <yd-button  size="large" type="primary" @click.native="buttonoperaterefuseClick" style="background-color:#3cc8a8;color:white;border-left: 1px solid #ffffff ">
                    拒绝
                </yd-button>
            </div>
        </div>

        <!-- 路由匹配到的组件将渲染在这里 -->
        <router-view></router-view>



    </div>

</template>

<script>
    import {ordercancel,orderDetails,orderoperateNow} from "../../pcof/post";
    import {userInfoData,qn_domain} from '../../globalVariables'
    import TabsComponent from "@/components/TabsComponent.vue";
    export default {
        name: "officeDetailandprogress",
        data() {
            return {
                orderUuid: '',
                buttonName:'',
                buttonfristName:'',
                buttonsecondName:'',
                currentHandler:'',//当前的操作对象
                selfuuid:'',//用户的自己id
                applierUuid:'',//发起人
                type:'',
                isshowButton:false,//一个按钮
                isshowshenhe:false,//两个按钮 审核
                isshowjingban:false,//两个按钮 经办
                dataList:[],
                state:'',
                tabsOne: [
                    {id: 1, text: "详情"},
                    {id: 2, text: "进度"},
                ],
                tabIndex: 1,

            }

        },
        components: {

            TabsComponent,
        },

        methods:{
            switchHandler(payload) {

                console.log(payload.index);
                if (payload.index === 0) {

                    this.$router.replace({name: 'officeOrderDetail', params: {orderUuid: this.orderUuid}});
                } else if (payload.index === 1) {
                    this.$router.replace({name: 'officeProgress', params: {orderUuid: this.orderUuid,type:this.type}});
                }
            },
           async ordercancelClick()
            {
                // *办公用品撤销 orderUuid 单子的id  ordercancel
                var mobile = JSON.parse(localStorage.getItem(userInfoData)).mobile;
                this.$dialog.loading.open('加载中...');
                var response = await ordercancel(mobile,this.orderUuid);
                if (response.data.code === 200) {
                    this.$dialog.loading.close();
                    this.$dialog.toast({
                        mes: '已撤销',
                        timeout: 1500
                    });
                    this.$router.back(-1);

                }else
                {
                    this.$dialog.loading.close();
                    this.$dialog.toast({
                        mes: response.data.msg,
                        timeout: 1500
                    });
                }
            },
            async buttonClick() {

                //    ToBeApproval("00", "待审批"), 是自己可以撤销 不是自己是审核 同意 拒绝
                //    Approval("01", "审批中"), 是同意 拒绝
                //    ToBeDistribution("02", "待配送"),经办按钮
                //    Distribution("03", "配送中"), 确认收货
                //    Canceled("85", "已撤销"),
                //    Refuse("90", "被拒绝"),
                //    Completed("95", "待评价"), 评价
                //    Evaluated("99", "已完成");
                if (this.buttonName === '撤销') {

                    let that = this;
                    this.$dialog.confirm({
                        title: '',
                        mes: '撤销后该条流程无法继续进行',
                        opts: [{
                            txt: '撤销流程',
                            color: true,
                            callback: () => {
                                that.ordercancelClick();

                            }
                        },
                            {
                                txt: '取消',
                                color: false,
                                callback: () => {
                                }
                            }
                        ]
                    });


                } else if (this.buttonName === '确认收货') {
                    console.log(this.dataList);

                    this.$router.replace({name: 'voucherShouhuonum', params: {applicationUuid: this.orderUuid,dataAr:this.dataList,type:'1'}});//1 是办公用品 2是凭证请领

                } else if (this.buttonName === '评价') {

                    this.$router.replace({name: 'customEvaluate', params: {type: '1',uuid: this.orderUuid}});//type //1 是办公用品 2是凭证请领

                }
            },
            buttonexamineacceptClick()//审核同意按钮
            {
                this.$router.replace({name: 'officeExaminandoperate', params: {type: '1',orderUuid:this.orderUuid}});//type //1 审核同意 2是审核拒绝 3经办拒绝

            },
            buttonexaminerefuseClick(){//审核拒绝按钮
                this.$router.replace({name: 'officeExaminandoperate', params: {type: '2',orderUuid:this.orderUuid}});//type //1 审核同意 2是审核拒绝 3经办拒绝
            },
            async buttonoperateNowClick()//经办立即处理
            {
                var mobile = JSON.parse(localStorage.getItem(userInfoData)).mobile;
                this.$dialog.loading.open('加载中...');
                var response = await orderoperateNow(mobile,this.orderUuid);
                if (response.data.code === 200) {
                    this.$dialog.loading.close();
                    this.$router.replace({name: 'wait'});
                    this.$dialog.toast({
                        mes: '已发送给供应商',
                        timeout: 1500
                    });
                }
                else
                {
                    this.$dialog.loading.close();
                    this.$dialog.toast({
                        mes: response.data.msg,
                        timeout: 1500
                    });
                }

            },
            buttonoperaterefuseClick(){//经办拒绝按钮
                this.$router.replace({name: 'officeExaminandoperate', params: {type: '3',orderUuid:this.orderUuid}});//type //1 审核同意 2是审核拒绝 3经办拒绝

            },

        },
       async created() {

            //接受上个页面传值 在实例创建完成后被立即调用
            this.orderUuid =  this.$route.params.orderUuid;
            this.currentHandler=this.$route.params.currentHandler;//当前的操作对象
           console.log('当前的操作对象'+this.currentHandler);

           this.applierUuid=this.$route.params.applierUuid;//发起人
           console.log('发起人的'+this.currentHandler);

           this.state = this.$route.params.state;
           this.type=this.$route.params.type;

           this.$router.replace({name: 'officeOrderDetail', params: {orderUuid: this.orderUuid}});
            this.selfuuid=JSON.parse(localStorage.getItem(userInfoData)).uuid;

           var mobile = JSON.parse(localStorage.getItem(userInfoData)).mobile;
           console.log(this.orderUuid);
           this.$dialog.loading.open('加载中...');

           var response = await orderDetails(mobile, this.orderUuid);
           if (response.data.code === 200) {
               this.$dialog.loading.close();
               this.dataList = response.data.data.commodities;
                  console.log(this.dataList);
           } else {
               this.$dialog.loading.close();
               this.$dialog.toast({
                   mes: response.data.msg,
                   timeout: 1500
               });
           }
        //type 0是待办页 1是历史页来的(不显示button)

            //    ToBeApproval("00", "待审批"), 是自己可以撤销 不是自己是审核 同意 拒绝
            //    Approval("01", "审批中"), 是同意 拒绝
            //    ToBeDistribution("02", "待配送"),经办按钮
            //    Distribution("03", "配送中"), 确认收货
            //    Canceled("85", "已撤销"),
            //    Refuse("90", "被拒绝"),
            //    Completed("95", "待评价"), 评价
            // //    Evaluated("99", "已完成");

           // currentHandler:'',//当前的操作对象
           //     selfuuid:'',//用户的自己id
           //     applierUuid:'',//发起人
           if (this.type === '0') {
                 if (this.state === '00') {
                     //发起人是自己可以撤销，不是自己 等待审核
                     // "待审批"), 是自己可以撤销 不是自己是审核 同意 拒绝
                     if(this.applierUuid ===this.selfuuid)
                    {
                        this.buttonName = '撤销';
                        this.isshowButton = true;
                        this.isshowshenhe = false;
                        this.isshowjingban =false;
                    }else
                    {
                        this.isshowButton = false;
                        this.isshowshenhe = true;
                        this.isshowjingban =false

                    }

                } else if (this.state === '01') {
                   //"审批中"), 是同意 拒绝
                     //审批中 发起人是自己就不能审核
                     if (this.applierUuid === this.selfuuid) {

                         this.isshowButton = false;
                         this.isshowshenhe = false;
                         this.isshowjingban =false;

                     } else {

                         this.isshowButton = false;
                         this.isshowshenhe = true;
                         this.isshowjingban =false;

                     }
                 }else if (this.state === '02') {
                     // "待配送"),经办按钮
                     // 经办 经办人 当前处理的id是自己
                     if (this.currentHandler === this.selfuuid) {
                         this.isshowButton = false;
                         this.isshowshenhe = false;
                         this.isshowjingban =true;

                     } else {

                         this.isshowButton = false;
                         this.isshowshenhe = false;
                         this.isshowjingban =false;
                     }
                 }else if (this.state === '03') {
                     ///"配送中"), 确认收货
                     // 确认收货 发起人是自己
                     if (this.applierUuid === this.selfuuid) {
                         this.buttonName = '确认收货';
                         this.isshowButton = true;
                         this.isshowshenhe = false;
                         this.isshowjingban =false;

                     } else {

                         this.isshowButton = false;
                         this.isshowshenhe = false;
                         this.isshowjingban =false;

                     }
                 }else if (this.state === '95') {
                     //"待评价"), 评价
                     // 评价 发起人是自己
                     if (this.applierUuid === this.selfuuid) {
                         this.buttonName = '评价';
                         this.isshowButton = true;
                         this.isshowshenhe = false;
                         this.isshowjingban =false;

                     }else
                     {
                         this.isshowButton = false;
                         this.isshowshenhe = false;
                         this.isshowjingban =false;
                     }

                } else {
                     this.isshowButton = false;
                     this.isshowshenhe = false;
                     this.isshowjingban =false;
                }

              } else {
                  this.isshowButton = false;
                  this.isshowshenhe = false;
                  this.isshowjingban =false;
            }
        },


    }
</script>

<style lang="scss">
    .repair-task-layout {
        /*导航栏浮动设置*/
        .repair-tab-part {
            /*position:sticky;*/
            /*position: -webkit-sticky;*/
            /*top: 0;*/
            /*left: 0;*/
            /*width: 100%;*/
            /*z-index: 999;*/


            z-index:2000;
            position: fixed;
            width: 100%;
            height: 1rem;
            top: 0;
            left: 0;
        }

    }
    .button-backgrond
    {
        position: fixed;
        bottom: 0px;
        left: 0;
        width: 100%;
        background-color: #f9f9f9;
        z-index: 3000;
    }

</style>